#include "../include/FireworkLines.h"

#include <algorithm>
#include <iterator>

#include "../include/utilities.h"

void FireworkLines::initFireworkParticles() {
	
	std::uniform_int_distribution<> lineCountDis(40, 120);
	std::normal_distribution<float> speedDis(20, 5);
	std::uniform_int_distribution<> lengthDis(-2, -2);
	
	uint8_t lineCount = lineCountDis(m_gen);
	float initSpeed;
	std::vector<Vector3> speedList;
	for (int i = 0; i < lineCount; ++i) {
		initSpeed = 10 + std::fabs(speedDis(m_gen));
		Vector3 normal = getRandomNormal(-90, 90, 0, 360);
		Vector3 speed = Vector3Scale(normal, initSpeed);
		speedList.push_back(speed);
	}
	Color color = getRandomColor();
	addNewBombs(m_pos, speedList, color, 3 + lengthDis(m_gen));
	
	float speedRatio = 0.7;
	float iterRatio = 0.5;
	std::uniform_real_distribution<float> speedNewDis(-1, 1);
	float iterCount = 0;
	while (isToDo(iterRatio)) {
		iterCount++;
		speedList.clear();
		
		color = getRandomColor();
		lineCount = lineCountDis(m_gen);
		initSpeed = initSpeed * speedRatio;
		for (int i = 0; i < lineCount; ++i) {
			float speedRandom = initSpeed + speedNewDis(m_gen) * powf(speedRatio, iterCount);
			Vector3 normal = getRandomNormal(-90, 90, 0, 360);
			Vector3 speed = Vector3Scale(normal, speedRandom);
			speedList.push_back(speed);
		}
		addNewBombs(m_pos, speedList, color, 3 + lengthDis(m_gen));
	}
}
